import Mock from "mockjs"
import { param2Obj } from '../utils/url'

let list=[]
for(var i=0;i<100;i++){
    list.push({
            id:Mock.mock('@increment(10000)'),
            name: Mock.mock('@ctitle(3, 5)'),
            cell: '1231456345',
            date: '¥2314.00',
            dates:Mock.mock('@integer(1, 30)'), 
            income:Mock.mock('@integer(1, 10)'),
            pay:Mock.mock('@now()'),
    
    })
}
export default {

    getStuData:(config)=>{
       let{search,page,pageSize}=param2Obj(config.url)
       let newList= list.filter((item,index)=>{
            return item.name.indexOf(search) !=-1
           
        })
        let newList2= newList.filter((item,index)=>{
            return (page-1)*pageSize<=index && index<page*pageSize
        })
        return{
            code:200,
            msg:"请求成功",
            data:newList2
        }
    },
    deleteMock:config=>{
        console.log('config',config);
        let {id}=JSON.parse(config.body)
        let newlist=list.filter(item=>{
            return item.id != id
        })
        list=newlist
        return{
            code:200,
            msg:'删除成功',
            data:null
        }
    },
    updateMock:config=>{
        console.log(JSON.parse(config.body))
        let {id,name,cell,date,dates, income,pay}=JSON.parse(config.body)
        list.forEach(item=>{
            if(item.id==id){

          
            item.id=id
            item.name=name
            item.cell=cell
            item.date=date
            item.dates=dates 
            item.income=income
            item.pay=pay
        }
        })
        return{
            code:200,
            msg:'删除成功',
            data:null
        }
    }
}